﻿var MyTree = function(req, exp, mod) {
    var setting = {
        check: {
            enable: true,
            //chkboxType:{ "Y" : "ps", "N" : "s" }
            chkboxType: {
                "Y": "s",
                "N": "s"
            }
        },
        data: {
            simpleData: {
                enable: true
            }
        },
        callback: {
            onClick: function(e) {
                console.log(e)
            }
        },
        edit: {
            enable: false
        },
        view: {
            fontCss: {
                color: "#000"
            }
        },
        callback: {
            onClick: function(event, treeId, treeNode) {
                this.getZTreeObj("mcTree").checkNode(treeNode);
            }
        }
    };

    /**
     *
     * @param re
     * @private
     */
    function _succ(re) {
        var _result = re.result || re;
        var _rootData = _result.resultDatas.root,
            _afterData = [];
        $.each(_rootData, function(index, item) {
            if (item.pId == 1) {
                item.open = 0;
            }
            _afterData.push(item);
        });
        $.fn.zTree.init($("#mcTree"), setting, _afterData);
    }

    function _write() {
        $.ajax({
            type: "GET",
            dataType: "json",
            url: 'data/tree.json',
            beforeSend: function(xhr) {
                xhr.withCredentials = true;
            },
            xhrFields: {
                withCredentials: true
            }
        }).done(_succ);
    }
    return {
        initTree: _write
    }
}();
